/*
 * Copyright 2010 J Patrick Davenport
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package v4view.web;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;

import v4view.web.ext.BindingSelect;
import v4view.web.ext.Person;

public class RealTest {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(final String[] args) throws IOException {
		run();
		run();
		run();
		run();
		run();
		run();
	}

	private static void run() throws IOException {
		final long start = System.currentTimeMillis();
		final Html html = new Html();
		html.setPrettyPrint(false);
		html.setPageTitle("An example page");
		final Div firstDiv = new Div();
		final List<Person> people = new ArrayList<Person>();
		people.add(new Person("Patrick", "12312123"));

		final BindingSelect binding = new BindingSelect().setOptions(people).setDisplayMethod("firstName").setValueMethod("id");
		html.getBody()
				.setStyle("border: 1px solid black;")
				.addPageElement(firstDiv);

		firstDiv.addPageElement(new Content("This is my content, it could be DB created."))
				.addPageElement(new Image("/img/mypic.jpg", "why is alt text required?"))
				.addPageElement(new Text("person.firstName", "Patrick").setOnClick("alert('Sup, Mr. Man?');"))
				.addPageElement(new Hidden("ssn", "621225987"))
				.addPageElement(binding);

		final MockHttpServletRequest req = new MockHttpServletRequest();
		req.setContextPath("/MyApp");
		final MockHttpServletResponse res = new MockHttpServletResponse();
		html.render(req, res);
		System.out.println("Execute took: " + (System.currentTimeMillis() - start));
		System.out.println(res.getContentAsString());
	}
}
